<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('roles', function (Blueprint $table) {
            $table->id();
            $table->string('name', 100)->unique()->comment('角色名称');
            $table->string('code', 50)->unique()->comment('角色编码');
            $table->text('description')->nullable()->comment('角色描述');
            $table->enum('type', ['system', 'custom'])->default('custom')->comment('角色类型');
            $table->enum('status', ['active', 'inactive'])->default('active')->comment('角色状态');
            $table->integer('sort_order')->default(0)->comment('排序权重');
            $table->json('permissions')->nullable()->comment('角色权限');
            $table->timestamps();
            
            // 索引
            $table->index(['code', 'status']);
            $table->index(['name', 'status']);
            $table->index(['type', 'status']);
            $table->index('sort_order');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('roles');
    }
};
